package com.packet.cheng;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;  
import java.util.concurrent.Executors;
import com.packet.cheng.service.AService;
import com.packet.cheng.service.BService;
import com.packet.cheng.service.CService;
  
public class Main {  
    public static void main(String[] args) {  
        int n = 100; // 参数  
        CompletableFuture future = CompletableFuture.supplyAsync(() -> AService.get(), executorService())
                         .thenComposeAsync((a) -> CompletableFuture.supplyAsync(() -> BService.get(), executorService()), executorService())  
                         .thenComposeAsync((b) -> CompletableFuture.supplyAsync(() -> CService.get(1,20), executorService()), executorService())
                         .thenAcceptAsync((result) -> System.out.println(result * 100)); // 乘以100并输出结果

        // 处理异常情况，异常情况返回0
        future.exceptionally(e->{
            return 0;
        });
    }  
  
    // 显示指定线程池
    private static ExecutorService executorService() {  
        return Executors.newFixedThreadPool(10);  
    }  
}